package com.ant.collect.common;

import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author hzd
 * @version 1.0
 * @date 2023/7/19 10:34
 */
@Component
public class ApplicationContextService {

    public static ApplicationContext applicationContext;

    public static void setApplicationContext(ApplicationContext applicationContext) {
        ApplicationContextService.applicationContext = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return ApplicationContextService.applicationContext;
    }

    public static Object getBean(String name) {
        return getApplicationContext().getBean(name);
    }

    public static <T>T getBean(Class clazz) {
        return (T)getApplicationContext().getBean(clazz);
    }

    public static <T>T getBean(String name, Class clazz) {
        return (T)getApplicationContext().getBean(name,clazz);
    }

}
